<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="微盟订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入微盟订单编号"
          clearable
          @input="queryParams.orderNo = queryParams.orderNo.replace(/\D/g,'')"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物流公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入物流公司名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="快递单号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入快递单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代客订单编号" prop="outerOrderNo">
        <el-input
          v-model="queryParams.outerOrderNo"
          placeholder="请输入代客订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--
         <el-form-item label="订单状态变更时间信息(时间毫秒值)" prop="value">
            <el-input
              v-model="queryParams.value"
              placeholder="请输入订单状态变更时间信息(时间毫秒值)"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="收货时间，包裹确认收货必填" prop="receiveTime">
            <el-input
              v-model="queryParams.receiveTime"
              placeholder="请输入收货时间，包裹确认收货必填"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="买家备注" prop="buyerRemark">
            <el-input
              v-model="queryParams.buyerRemark"
              placeholder="请输入买家备注"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
      <el-form-item label="外部订单项 ID" prop="outItemId">
        <el-input
          v-model="queryParams.outItemId"
          placeholder="请输入外部订单项 ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省份" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区/县" prop="county">
        <el-input
          v-model="queryParams.county"
          placeholder="请输入区/县"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="预计配送开始时间，时间戳，毫秒级" prop="expectReceivedStartTime">
          <el-input
            v-model="queryParams.expectReceivedStartTime"
            placeholder="请输入预计配送开始时间，时间戳，毫秒级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="预计配送时间，时间戳，毫秒级" prop="expectReceivedEndTime">
          <el-input
            v-model="queryParams.expectReceivedEndTime"
            placeholder="请输入预计配送时间，时间戳，毫秒级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="核销人ID-自提" prop="writeOffId">
          <el-input
            v-model="queryParams.writeOffId"
            placeholder="请输入核销人ID-自提"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="物流公司名称" prop="companyName">
          <el-input
            v-model="queryParams.companyName"
            placeholder="请输入物流公司名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="预计配送时间，时间戳，毫秒级" prop="expectReceivedDate">
          <el-input
            v-model="queryParams.expectReceivedDate"
            placeholder="请输入预计配送时间，时间戳，毫秒级"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="包裹发货时间，包裹发货必填。" prop="deliveryTime">
          <el-input
            v-model="queryParams.deliveryTime"
            placeholder="请输入包裹发货时间，包裹发货必填。"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      <el-form-item label="发货方式" prop="deliveryMethod">
        <el-input
          v-model="queryParams.deliveryMethod"
          placeholder="请输入发货方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        <el-form-item label="收货人完整地址信息" prop="receiverAddress">
            <el-input
              v-model="queryParams.receiverAddress"
              placeholder="请输入收货人完整地址信息"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
      <el-form-item label="收货人姓名" prop="receiverName">
        <el-input
          v-model="queryParams.receiverName"
          placeholder="请输入收货人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货人电话" prop="receiverMobile">
        <el-input
          v-model="queryParams.receiverMobile"
          placeholder="请输入收货人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包裹名称" prop="packageName">
        <el-input
          v-model="queryParams.packageName"
          placeholder="请输入包裹名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
                   v-hasPermi="['Logistics:logistics:import']">导入
        </el-button>
      </el-col>

      <!--    <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['Logistics:logistics:edit']"
            >修改
            </el-button>
          </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['Logistics:logistics:remove']"
        >删除
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['Logistics:logistics:export']"
        >导出
        </el-button>
      </el-col>
    <!--  <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['Logistics:logistics:add']"
        >新增
        </el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="logisticsList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center"
        :index="(i) => (pageSize * (pageNum - 1)) + i + 1"
      />
      <el-table-column label="微盟订单编号" align="center" prop="orderNo"/>
      <el-table-column label="代客订单编号" align="center" prop="outerOrderNo" width="180"/>

<!--      <el-table-column label="快递单号" align="center" prop="number"/>
      <el-table-column label="物流公司代码" align="center" prop="companyCode"/>
       <el-table-column label="物流公司名称" align="center" prop="companyName"/>
        <el-table-column label="配送编码" align="center" prop="deliveryNo" width="180"/>
             <el-table-column label="外部订单项ID" align="center" prop="outItemId" width="180"/>
             <el-table-column label="商品数量" align="center" prop="skuNum"/>
             <el-table-column label="发货人完整地址信息" align="center" prop="senderAddress"  width="180"/>
             <el-table-column label="发货人电话" align="center" prop="senderMobile" />
             <el-table-column label="发货人名称" align="center" prop="senderName"/>
             <el-table-column label="操作门店的组织 ID" align="center" prop="processVid"  width="160"/>
             <el-table-column label="我的品牌" align="center" prop="processVidName"  width="100"/>
             <el-table-column label="预计配送开始时间" align="center" prop="expectReceivedStartTime"/>
             <el-table-column label="预计配送时间" align="center" prop="expectReceivedEndTime"/>
             <el-table-column label="核销人ID" align="center" prop="writeOffId"/>
             <el-table-column label="预计配送时间" align="center" prop="expectReceivedDate"/>
             <el-table-column label="预计配送类型" align="center" prop="expectReceivedType"/>
             <el-table-column label="包裹发货时间" align="center" prop="deliveryTime"/>
             <el-table-column label="发货方式" align="center" prop="deliveryMethod"/>
             <el-table-column label="收货人完整地址信息" align="center" prop="receiverAddress"  width="180"/>
             <el-table-column label="乡镇/街道" align="center" prop="area"/>
             <el-table-column label="邮编" align="center" prop="zip"/>
             <el-table-column label="详细地址" align="center" prop="address"/>
             <el-table-column label="经度" align="center" prop="longitude"/>
             <el-table-column label="维度" align="center" prop="latitude"/>
             <el-table-column label="省份" align="center" prop="province"/>
             <el-table-column label="城市" align="center" prop="city"/>
             <el-table-column label="区/县" align="center" prop="county"/>
             <el-table-column label="乡镇/街道编码" align="center" prop="areaCode"/>
             <el-table-column label="城市编码" align="center" prop="cityCode"/>
             <el-table-column label="区/县编码" align="center" prop="countyCode"/>
             <el-table-column label="省份编码" align="center" prop="provinceCode"/>
             <el-table-column label="收货人姓名" align="center" prop="receiverName"/>
             <el-table-column label="收货人电话" align="center" prop="receiverMobile"/>
             <el-table-column label="订单状态变更时间时间类型" align="center" prop="type"/>
             <el-table-column label="订单状态变更时间单位" align="center" prop="value"/>
             <el-table-column label="收货时间" align="center" prop="receiveTime"/>
             <el-table-column label="买家备注" align="center" prop="buyerRemark"/>
             <el-table-column label="商家备注" align="center" prop="remark"/>
             <el-table-column label="包裹名称" align="center" prop="packageName"/>
             <el-table-column label="确认收货类型" align="center" prop="confirmType"/>
             <el-table-column prop="orderStatus" label="订单状态" width="100">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.wm_order_status" :value="scope.row.orderStatus"/>
                </template>
             </el-table-column>-->

      <el-table-column label="物流状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_logistics_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateBy" />
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
     <!--     <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['Logistics:logistics:edit']"
          >修改
          </el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['Logistics:logistics:remove']"-->
<!--          >删除-->
<!--          </el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetails(scope.row)"
            v-hasPermi="['business:orderInfo:edit']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 物流详情弹窗 -->
    <el-dialog
      :title="'物流详情 ： 订单号：' + currentRow.outerOrderNo"
      :visible.sync="detailsDialogVisible"
      width="800px"
    >
      <el-table :data="detailsList" border>
        <el-table-column
          label="序号"
          type="index"
          width="50"
          align="center"
          :index="(i) => i + 1"
        />
        <el-table-column label="快递单号" align="center" prop="number"/>
        <el-table-column label="物流公司名称" align="center" prop="companyName"/>
      </el-table>
      <template #footer>
        <el-button @click="detailsDialogVisible = false">关闭</el-button>
      </template>
    </el-dialog>

    <!-- 添加或修改物流信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="微盟合同号" prop="orderNo">
              <el-input v-model="form.orderNo" placeholder="请输入微盟合同号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单编号" prop="outerOrderNo">
              <el-input v-model="form.outerOrderNo" placeholder="请输入订单编号"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="快递单号" prop="number">
              <el-input v-model="form.number" placeholder="请输入快递单号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物流名称" prop="companyName">
              <el-select v-model="form.companyName">
                <el-option
                  v-for="dict in dict.type.sys_logistics_company"
                  :key="dict.value"
                  :label="dict.label"
                  :value="(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url"
                 :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess"
                 :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
                   @click="importTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {addLogistics, delLogistics, getLogistics, listLogistics, updateLogistics,getLogisticsInfo,distinctMroLogisticsList,getLogisticsInfoByOuterOrderNo} from "@/api/business/logistics";
  import {getToken} from '@/utils/auth'

  export default {
    name: "Logistics",
    dicts: ['sys_logistics_company', 'wm_order_status', 'sys_logistics_status'],
    data() {
      return {
        detailsList: [],   // 弹窗内的详情数据
        detailsDialogVisible: false,
        currentRow: {},    // 当前点击的那一行

        upload: {
          // 是否显示弹出层（商品信息导入）
          open: false,
          // 弹出层标题（商品信息导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 设置上传的请求头部
          headers: {Authorization: "Bearer " + getToken()},
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + '/Logistics/logistics/importMorLogisticsInfoFile',
        },
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 物流信息表格数据
        logisticsList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderNo: null,
          orderStatus: null,
          type: null,
          value: null,
          receiveTime: null,
          buyerRemark: null,
          outItemId: null,
          skuNum: null,
          area: null,
          zip: null,
          address: null,
          longitude: null,
          latitude: null,
          province: null,
          city: null,
          county: null,
          areaCode: null,
          cityCode: null,
          countyCode: null,
          provinceCode: null,
          senderAddress: null,
          senderMobile: null,
          senderName: null,
          processVid: null,
          processVidName: null,
          companyCode: null,
          number: null,
          expectReceivedStartTime: null,
          expectReceivedEndTime: null,
          writeOffId: null,
          companyName: null,
          expectReceivedDate: null,
          expectReceivedType: null,
          deliveryTime: null,
          deliveryMethod: null,
          receiverAddress: null,
          receiverName: null,
          receiverMobile: null,
          packageName: null,
          confirmType: null,
          status: null,
          outerOrderNo: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          orderNo: [
            {required: true, message: "订单编号不能为空", trigger: "blur"}
          ],
          orderStatus: [
            {required: true, message: "订单状态不能为空", trigger: "change"}
          ],
          type: [
            {required: true, message: "订单状态变更时间不能为空", trigger: "change"}
          ],
          value: [
            {required: true, message: "订单状态变更时间单位不能为空", trigger: "blur"}
          ],
          outItemId: [
            {required: true, message: "外部订单项 ID不能为空", trigger: "blur"}
          ],
          skuNum: [
            {required: true, message: "商品数量不能为空", trigger: "blur"}
          ],
          area: [
            {required: true, message: "乡镇/街道不能为空", trigger: "blur"}
          ],
          zip: [
            {required: true, message: "邮编不能为空", trigger: "blur"}
          ],
          address: [
            {required: true, message: "详细地址不能为空", trigger: "blur"}
          ],
          longitude: [
            {required: true, message: "经度不能为空", trigger: "blur"}
          ],
          latitude: [
            {required: true, message: "维度不能为空", trigger: "blur"}
          ],
          province: [
            {required: true, message: "省份不能为空", trigger: "blur"}
          ],
          city: [
            {required: true, message: "城市不能为空", trigger: "blur"}
          ],
          county: [
            {required: true, message: "区/县不能为空", trigger: "blur"}
          ],
          areaCode: [
            {required: true, message: "发货人所在乡镇/街道编码不能为空", trigger: "blur"}
          ],
          cityCode: [
            {required: true, message: "发货人所在城市编码不能为空", trigger: "blur"}
          ],
          countyCode: [
            {required: true, message: "发货人所在区/县编码不能为空", trigger: "blur"}
          ],
          provinceCode: [
            {required: true, message: "发货人所在省份编码不能为空", trigger: "blur"}
          ],
          senderAddress: [
            {required: true, message: "发货人完整地址信息不能为空", trigger: "blur"}
          ],
          senderMobile: [
            {required: true, message: "发货人电话不能为空", trigger: "blur"}
          ],
          senderName: [
            {required: true, message: "发货人名称不能为空", trigger: "blur"}
          ],
          processVid: [
            {required: true, message: "操作门店的组织 ID不能为空", trigger: "blur"}
          ],
          processVidName: [
            {required: true, message: "我的品牌不能为空", trigger: "blur"}
          ],
          companyCode: [
            {required: true, message: "物流公司代码不能为空", trigger: "blur"}
          ],
          number: [
            {required: true, message: "快递单号不能为空", trigger: "blur"}
          ],
          expectReceivedStartTime: [
            {required: true, message: "预计配送开始时间", trigger: "blur"}
          ],
          expectReceivedEndTime: [
            {required: true, message: "预计配送时间", trigger: "blur"}
          ],
          writeOffId: [
            {required: true, message: "核销人ID-自提不能为空", trigger: "blur"}
          ],
          companyName: [
            {required: true, message: "物流公司名称不能为空", trigger: "blur"}
          ],
          expectReceivedDate: [
            {required: true, message: "预计配送时间", trigger: "blur"}
          ],
          expectReceivedType: [
            {required: true, message: "预计配送类型不能为空", trigger: "change"}
          ],
          deliveryMethod: [
            {required: true, message: "发货方式不能为空", trigger: "blur"}
          ],
          receiverAddress: [
            {required: true, message: "收货人完整地址信息不能为空", trigger: "blur"}
          ],
          receiverName: [
            {required: true, message: "收货人姓名不能为空", trigger: "blur"}
          ],
          receiverMobile: [
            {required: true, message: "收货人电话不能为空", trigger: "blur"}
          ],
          confirmType: [
            {required: true, message: "确认收货类型不能为空", trigger: "change"}
          ],
        },
        pageNum: 1,
        pageSize: 50,
      };
    },
    created() {
      this.getList();
    },
    methods: {
      handleDetails(row) {
        this.currentRow = row;
        this.detailsDialogVisible = true;
        // 根据 orderNo 或 outerOrderNo 查询详情数据
        this.getLogisticsInfoByOuterOrderNo(row.outerOrderNo);
      },
      getLogisticsInfoByOuterOrderNo(outerOrderNo) {
        // 调用后端 API 获取物流详情数据
        this.loading = true;
        getLogisticsInfoByOuterOrderNo(outerOrderNo).then(response => {
          this.detailsList = response.data;
        }).finally(() => {
          this.loading = false;
        });
      },

      /** 打开导入弹框 */
      handleImport() {
        this.upload.title = "物流信息导入";
        this.upload.open = true;
      },
      handleImportSuccess(response) {
        this.$modal.msgSuccess('导入成功');
        this.importDialogVisible = false;
        this.getList(); // 重新加载数据
      },
      handleImportError(err) {
        this.$modal.msgError('导入失败');
      },
      beforeUpload(file) {
        const isExcel = file.type === 'application/vnd.ms-excel' || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
        if (!isExcel) {
          this.$modal.msgError('只能上传Excel文件');
        }
        return isExcel;
      },
      /** 查询物流信息列表 */
      getList() {
        this.loading = true;
        distinctMroLogisticsList(this.queryParams).then(response => {
          this.logisticsList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          deliveryNo: null,
          orderNo: null,
          orderStatus: null,
          type: null,
          value: null,
          receiveTime: null,
          buyerRemark: null,
          outItemId: null,
          skuNum: null,
          area: null,
          zip: null,
          address: null,
          longitude: null,
          latitude: null,
          province: null,
          city: null,
          county: null,
          areaCode: null,
          cityCode: null,
          countyCode: null,
          provinceCode: null,
          senderAddress: null,
          senderMobile: null,
          senderName: null,
          processVid: null,
          processVidName: null,
          companyCode: null,
          number: null,
          expectReceivedStartTime: null,
          expectReceivedEndTime: null,
          writeOffId: null,
          companyName: null,
          expectReceivedDate: null,
          expectReceivedType: null,
          deliveryTime: null,
          deliveryMethod: null,
          receiverAddress: null,
          receiverName: null,
          receiverMobile: null,
          remark: null,
          packageName: null,
          confirmType: null,
          status: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.deliveryNo)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加物流信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const deliveryNo = row.deliveryNo || this.ids
        getLogistics(deliveryNo).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改物流信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.deliveryNo != null) {
              updateLogistics(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addLogistics(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const deliveryNos = row.deliveryNo || this.ids;
        this.$modal.confirm('是否确认删除物流信息编号为"' + deliveryNos + '"的数据项？').then(function () {
          return delLogistics(deliveryNos);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      },
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        const msg = response.message || response.msg || '导入完成';
        this.$alert(
          `<div style='overflow:auto;overflow-x:hidden;max-height:70vh;padding:10px 20px 0;'>${msg}</div>`,
          "导入结果",
          {dangerouslyUseHTMLString: true}
        );
        // 如果成功才刷新列表
        if (response.code === 200) {
          this.getList();
        }
      },
      // 下载模板
      importTemplate() {
        this.download(
          '/Logistics/logistics/importTemplate',
          {},
          `物流导入_模版_${new Date().getTime()}.xlsx`
        );
      },
      // 文件上传过程中的处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 提交上传表单，触发文件上传
      submitFileForm() {
        this.$refs.upload.submit();
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('Logistics/logistics/export', {
          ...this.queryParams
        }, `logistics_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
